﻿@model Bk.Model.PersonViewModel
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>修改资料</title>
    <style>
        .main-layout {
            display: flex;
            max-width: 1000px;
            margin: 30px auto 0 auto;
            min-height: 600px;
        }
        .sidebar {
            width: 220px;
            background: white;
            border-radius: 8px;
            padding: 15px 0;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            margin-right: 24px;
            flex-shrink: 0;
        }
        .content {
            flex: 1;
            background: white;
            padding: 25px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            min-width: 0;
        }
        .menu-item {
            padding: 12px 20px;
            cursor: pointer;
            transition: all 0.3s;
            color: #666;
        }

            .menu-item:hover {
                background: #f5f5f5;
                color: #333;
            }

            .menu-item.active {
                color: #1890ff;
                background: #e6f7ff;
                border-right: 3px solid #1890ff;
            }

            .menu-item a {
                text-decoration: none;
            }

        .form-group {
            margin-bottom: 20px;
        }

        input, select, textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 16px;
        }

        textarea {
            height: 100px;
            resize: vertical;
        }

        .counter {
            color: #666;
            font-size: 12px;
            text-align: right;
            margin-top: 4px;
        }

        button[type="submit"] {
            background: #3498db;
            color: white;
            padding: 12px 24px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="top-bar">
        <div class="user-info">
            <span class="username">@ViewBag.UserName</span>
        </div>
    </div>
    <div class="main-layout">
        <div class="sidebar">
            <div class="menu-item @(ViewBag.ActiveMenu == "Person" ? "active" : "")" onclick="location.href='@Url.Action("Person", "Home")'">基本信息</div>
            <div class="menu-item @(ViewBag.ActiveMenu == "Uploadface" ? "active" : "")" onclick="location.href='@Url.Action("Uploadface", "Home")'">上传头像</div>
            <div class="menu-item @(ViewBag.ActiveMenu == "Blog" ? "active" : "")" onclick="location.href='@Url.Action("Blog", "Home")'">我的博客</div>
            <div class="menu-item @(ViewBag.ActiveMenu == "ModifyData" ? "active" : "")" onclick="location.href='@Url.Action("ModifyData", "Home")'">修改资料</div>
            <div class="menu-item @(ViewBag.ActiveMenu == "ChangePassword" ? "active" : "")" onclick="location.href='@Url.Action("ChangePassword", "Home")'">修改密码</div>
            <div class="menu-item" onclick="location.href='@Url.Action("index", "Default")'">返回</div>
        </div>

        <div class="content">
            <h1>修改资料</h1>
            @using (Html.BeginForm("ModifyData", "Home", FormMethod.Post, new { id = "profileForm" }))
            {
                @Html.AntiForgeryToken()
                <div class="form-section">
                    <div class="input-group">
                        <label>昵称</label>
                        @Html.TextBoxFor(m => m.NickName)
                    </div>

                    <div class="input-group">
                        <label>性别</label>
                        @Html.DropDownListFor(m => m.Gender, new List<SelectListItem>
                        {
                            new SelectListItem{Text = "----请选择----", Value = ""},
                            new SelectListItem{Text = "男", Value = "男"},
                            new SelectListItem{Text = "女", Value = "女"},
                            new SelectListItem{Text = "其他", Value = "其他"}
                        }, new { required = "required" })
                    </div>

                    <div class="input-group">
                        <label>自我介绍（不多于150字）</label>
                        @Html.TextAreaFor(m => m.Introduction, new { maxlength = 150, id = "introduction" })
                        <div class="counter">
                            <span id="introCount">0</span>/150
                        </div>
                    </div>
                </div>

                <div class="form-section">
                    <label>个人描述（不多于150字）</label>
                    @Html.TextAreaFor(m => m.Description, new { maxlength = 150, id = "description" })

                    <div class="counter">
                        <span id="descCount">0</span>/150
                    </div>
                    <div class="counter">
                        <button type="submit">提交</button>
                    </div>
                </div>
            }
        </div>
    </div>
    <script>
        //基本信息跳转
        function Person() {
            window.location.href = 'Person';
        }
        //上传头像跳转
        function Uploadface() {
            window.location.href = 'Uploadface';
        }
        //我的博客跳转
        function Blog() {
            window.location.href = 'Blog';
        }
        //修改密码跳转
        function ChangePassword() {
            window.location.href = 'ChangePassword';
        }


        // 侧边栏菜单切换
        document.querySelectorAll('.menu-item').forEach(item => {
            item.addEventListener('click', function () {
                document.querySelectorAll('.menu-item').forEach(i => i.classList.remove('active'));
                this.classList.add('active');
            });
        });
        // 实时字数统计
        const intro = document.getElementById('introduction');
        const desc = document.getElementById('description');
        const introCount = document.getElementById('introCount');
        const descCount = document.getElementById('descCount');
        const syncCount = (el, counter) => counter.textContent = (el.value || '').length;
        [intro, desc].forEach((el) => {
            if (!el) return;
            el.addEventListener('input', () => {
                if (el === intro) syncCount(intro, introCount);
                if (el === desc) syncCount(desc, descCount);
            });
            // 初始化
            if (el === intro) syncCount(intro, introCount);
            if (el === desc) syncCount(desc, descCount);
        });

        // 表单验证
        // 让浏览器原生提交到后端，由服务器处理
    </script>
    @if (TempData["SuccessMessage"] != null)
    {
        <script>
            alert('@TempData["SuccessMessage"]');
        </script>
    }
</body>
</html>
